#ifndef MYTABLES_H
#define MYTABLES_H
#include <QObject>
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QTranslator>
#include <QSqlDatabase>

class mytables: public QObject
{
    Q_OBJECT
    Q_PROPERTY(int language READ language WRITE setLanguage NOTIFY languageChanged)
    Q_PROPERTY(int ngCount READ ngCount WRITE setNGCount NOTIFY ngCountChanged)
    Q_PROPERTY(int okCount READ okCount WRITE setOKCount NOTIFY okCountChanged)
    Q_PROPERTY(int pwdSwitch READ pwdSwitch WRITE setPwdSwitch NOTIFY pwdSwitchChanged)
    Q_PROPERTY(QString langToken READ langToken NOTIFY langTokenChanged)
    Q_PROPERTY(QVariantMap weighMap READ weighMap CONSTANT)
    Q_PROPERTY(QVariantList addrs READ addrs CONSTANT)
    Q_PROPERTY(int saveOK READ saveOK WRITE setSaveOK NOTIFY saveOKChanged)
public:
    explicit mytables(QApplication& app, QQmlApplicationEngine &engine, QObject* parent = nullptr);
    void getData();
    Q_INVOKABLE int language();
    Q_INVOKABLE bool setLanguage(int language);

    Q_INVOKABLE int ngCount();
    Q_INVOKABLE bool setNGCount(int ngCount);

    Q_INVOKABLE int okCount();
    Q_INVOKABLE bool setOKCount(int okCount);

    Q_INVOKABLE int pwdSwitch();
    Q_INVOKABLE bool setPwdSwitch(int pwdSwitch);

    Q_INVOKABLE QVariantMap weighMap();
    Q_INVOKABLE QVariantList addrs();

    Q_INVOKABLE QString langToken();
    QTranslator* translater();

    Q_INVOKABLE int saveOK();
    Q_INVOKABLE void setSaveOK(int saveOK);
signals:
    void langTokenChanged(QString langToken);
    void languageChanged(int language);
    void ngCountChanged(int ngCount);
    void okCountChanged(int okCount);
    void pwdSwitchChanged(int pwdSwitch);
    void saveOKChanged(int saveOK);
public slots:
    bool changePwd(QString newPwd);
    bool verifyPwd(QString pwd);
    bool saveWeightData(QString weight);
    bool slotSaveLanguage(int language);
    bool clearCount();
private:

    int m_saveOK = -1;
    QApplication& m_a;
    QQmlApplicationEngine& m_engine;
    QTranslator* m_trans;
    QSqlDatabase m_db;
};

#endif // MYTABLES_H
